using System;
using System.Collections.Generic;
using System.Text;
using PostSharp.Laos;

using Spring.Context.Support;
using Spring.Context;
using System.Diagnostics;
using System.Reflection;
using System.Web;

namespace B4ALL.Cache
{

    [Serializable]
    public class CacheAttribute : OnMethodBoundaryAspect
    {

        private Boolean enabled = true;

        public Boolean Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }



        private Boolean refresh = false;

        public Boolean Refresh
        {
            get { return refresh = false; }
            set { refresh = value; }
        }

        private Int32 duration = 0;
        public Int32 Duration
        {
            get { return duration; }
            set { duration = value; }
        }

        /// <summary>
        /// Defines a cachecontext and injects it in the current thread, so that next methods will be aware of the cachecontext.
        /// </summary>
        /// <param name="eventArgs"></param>
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            B4ALL.Common.Context.SetContext(ContextFactory.GetContext(enabled, refresh, duration));
        }
    }
}
